<?php

namespace app\admin\controller;

use app\common\entity\BackResult;
use app\Request;
use app\common\service\BannerService;

class Banner extends Base
{

    public function index(Request $request)
    {
        $page = $request->param("page", 1);
        $pageSize = $request->param('pageSize', 10);
        $service = new BannerService();
        $data = $service->getList($page, $pageSize, []);
        return BackResult::success($data);
    }

    public function create(Request $request)
    {
        $data = $request->post();
        $service = new BannerService();
        $data = $service->create($data);
        return BackResult::success($data);
    }

    public function update(Request $request)
    {
        $id = (int)$request->param('id');
        if (!$id) {
            return BackResult::error(null, '参数异常');
        }
        $data = $request->post();
        $service = new BannerService();
        $data = $service->update($data, $id);
        return BackResult::success($data);
    }

    public function remove(Request $request)
    {
        $id = (int)$request->param('id');
        if (!$id) {
            return BackResult::error(null, '参数异常');
        }
        $service = new BannerService();
        $service->remove($id);
        return BackResult::success(null);
    }
}